package org.kabeja.parser;

import org.kabeja.dxf.DXFDocument;
import org.kabeja.dxf.DXFVariable;
import org.kabeja.dxf.entity.DXFHeader;

/**
 * @author shutao
 * @since 2022/4/25 14:23
 */
public class DXFHeaderSectionHandler implements DXFSectionHandler {
    public static final int VARIABLE_CODE = 9;
    private static final String SECTION_KEY = "HEADER";
    private DXFDocument doc;
    private DXFVariable variable = null;

    public DXFHeaderSectionHandler() {
    }

    @Override
    public String getSectionKey() {
        return SECTION_KEY;
    }

    @Override
    public void setDXFDocument(DXFDocument var1) {
        this.doc = var1;
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        if (var1 == VARIABLE_CODE) {
            this.variable = new DXFVariable(var2.getValue());
            this.doc.getDXFHeader().setVariable(this.variable);
        } else {
            this.parse(var1, var2);
        }

    }

    private void parse(int var1, DXFValue var2) {
        this.variable.setValue("" + var1, var2.getValue());
    }

    @Override
    public void endSection() {
        this.doc.getDXFHeader().paramConvert();
    }

    @Override
    public void startSection() {
        this.doc.setDXFHeader(new DXFHeader());
    }

    @Override
    public void releaseDXFDocument() {
        this.doc = null;
    }
}
